package com.teach.copy;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Scanner;

public class Socke002 {
	public static void main(String[] args) {
		try {
			Socket clint = new Socket("192.168.31.112",1000);
			System.out.println("连接上了服务器");
			
			Scanner scanner = new Scanner(System.in);
			
			 String line = null;	
			 
			OutputStream out = clint.getOutputStream();
			DataOutputStream dout = new DataOutputStream(out);
			
			 while (!"exit".equalsIgnoreCase((line = scanner.nextLine()))) {
				 System.out.println("向服务器端发送消息："+line);
				dout.writeUTF(line);
				dout.flush();
			}
			out.write(new byte [] {65,6,7,8,1});
			out.flush();
			System.out.println("发送了一段字节数组");
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
